<template>
  <div><!--当且仅当有一个div-->
    <el-container>
      <!--侧边栏-->
      <el-aside :width="asideWidth" style="min-height: 100vh; background-color: #2b303b;">
        <div style="height: 60px; color: #05cc95; display: flex; align-items: center; justify-content: center">
            <img src="@/assets/logo1.png" alt="" style="width: 40px; height: 40px">
            <span class="logo-title" v-show="!isCollapse">i实习管理平台</span>
        </div>

        <el-menu router
                 :collapse="isCollapse"
                 :collapse-transition="false"
                 background-color="#2b303b"
                 active-text-color="#fff" text-color="rgb(168 175 191)"
                 :default-active="$route.path"
                 style="border: none;">
          <el-menu-item index="/home">
              <i class="el-icon-s-home"></i>
              <span slot="title">首页</span>
          </el-menu-item>
          <el-menu-item index="/user" v-if="user.role === '管理员'">
            <i class="el-icon-attract"></i>
            <span slot="title">用户信息</span>
          </el-menu-item>
          <el-menu-item index="/notice" v-if="user.role === '管理员'">
            <i class="el-icon-s-comment"></i>
            <span slot="title">系统公告</span>
          </el-menu-item>
          <el-menu-item index="/logs" v-if="user.role === '管理员'">
            <i class="el-icon-news"></i>
            <span slot="title">系统日志</span>
          </el-menu-item>
          <el-menu-item index="/news" v-if="user.role === '管理员'">
            <i class="el-icon-message-solid"></i>
            <span slot="title">实习资料</span>
          </el-menu-item>
          <el-menu-item v-if="user.role === '教师'">
            <i class="el-icon-s-flag"></i>
            <span slot="title">实习计划</span>
          </el-menu-item>
          <el-menu-item v-if="user.role === '学生'">
            <i class="el-icon-s-management"></i>
            <span slot="title">实习任务</span>
          </el-menu-item>
          <el-menu-item v-if="user.role === '企业'">
            <i class="el-icon-s-opportunity"></i>
            <span slot="title">岗位管理</span>
          </el-menu-item>
          <el-menu-item index="/charts" v-if="user.role === '管理员'">
            <i class="el-icon-s-data"></i>
            <span slot="title">数据统计</span>
          </el-menu-item>
          <el-menu-item index="/orders" v-if="user.role === '管理员'">
            <i class="el-icon-s-data"></i>
            <span slot="title">订单管理</span>
          </el-menu-item>


          <el-submenu index="info" v-if="user.role === '管理员'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/stu"><i class="el-icon-s-custom"></i>学生信息</el-menu-item>
            <el-menu-item index="/tea"><i class="el-icon-s-platform"></i>导师信息</el-menu-item>
            <el-menu-item index="/qiy"><i class="el-icon-platform-eleme"></i>企业信息</el-menu-item>
          </el-submenu>
        </el-menu>


      </el-aside>

      <el-container>
        <!--头-->
        <el-header>
          <i :class="collapseIcon" style="font-size: 26px;" @click="handleCollapse"></i>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 20px">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{path: '$router.path'}">{{ $route.meta.name }}</el-breadcrumb-item>
          </el-breadcrumb>

          <div style="flex: 1; width: 0; display: flex; align-items: center; justify-content: flex-end">
            <i class="el-icon-quanping" style="font-size: 26px" @click="handleFulls"></i>
            <el-dropdown placement="bottom">
              <div style="display: flex; align-items: center; cursor: default">
                <img :src="user.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" alt="" style="width: 40px; height: 40px; margin: 0 5px; border-radius: 50%;">
                <span>{{ user.name }}</span>
              </div>

              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="$router.push('/person')">个人信息</el-dropdown-item>
                <el-dropdown-item @click.native="$router.push('/password')">修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>

        </el-header>

        <!--主体-->
        <el-main>
          <router-view @update:user="updateUser" />
        </el-main>
      </el-container>
    </el-container>


  </div>
</template>

<script>


export default {
  name: 'HomeView',
  data() {
    return {
      isCollapse: false,//不收缩
      asideWidth: '200px',
      collapseIcon: 'el-icon-s-fold',
      user: JSON.parse(localStorage.getItem('honey-user') || '{}'),
    }
  },
  mounted() { //页面加载完成之后触发
    /*axios.get('http://localhost:9090/user/selectAll').then(res => {
      console.log(res) //后台返回的数据
      this.users = res.data.data
    })*/
    /*request.get('/user/selectAll').then(res => {
      console.log(res) //后台返回的数据
      this.users = res.data
    })*/

    if (!this.user.id) {   // 当前的浏览器没有用户信息
      this.$router.push('/login')
    }

  },
  methods: {
    updateUser(user) { // 获取子组件传过来的的数据 更新当前页面的数据
      this.user = JSON.parse(JSON.stringify(user)) // 让父级的对象跟子级的对象毫无关联
    },
    logout() {
      localStorage.removeItem('honey-user') // 清楚当前的token和用户数据
      this.$router.push('/login')
    },
    handleCollapse() {
      this.isCollapse = !this.isCollapse
      this.asideWidth = this.isCollapse ? '64px':'200px'
      this.collapseIcon = this.isCollapse ? 'el-icon-s-fold':'el-icon-s-unfold'
    },
    handleFulls() {
      document.documentElement.requestFullscreen()
    }
  }
}
</script>


<style>
.el-menu-item {
  min-width: 0 !important;
  margin: 10px 17px 0 0;
  height: 46px !important;
  line-height: 46px!important;
  border-radius: 0 23px 23px 0;
  padding: 0 35px !important;
}
.el-submenu__title {
  height: 46px !important;
  line-height: 46px!important;
  padding: 0 35px !important;
  transition: color 0s;
  margin: 10px 17px 0 0;
  border-radius: 0 23px 23px 0;
}
.el-menu-item.is-active {
  background-color: #05cc95!important;
}
.el-menu-item:hover {
  color: #fff!important;
}
.el-submenu__title:hover *, .el-submenu__title:hover {
  color: #fff!important;
}
.el-aside {
  box-shadow: 2px 0 6px rgba(0,21,41, .35);
  color: #fff;
  transition: width .3s;

}


.el-submenu__title>i:nth-child(1) {
  margin-top: 2px;
}
.el-submenu__title>i.el-submenu__icon-arrow {
  margin-top: -5px;
}
.el-menu--collapse .el-submenu__title {
  padding: 0 15px!important;
}
.el-menu--collapse .el-tooltip {
  padding: 0 15px!important;
}

.logo-title {
  margin-left: 5px;
  font-size: 20px;
  color: white;
  font-family: 华文琥珀;
  transition: all .3s; /*0.3*/
}

.el-header {
  box-shadow: 2px 0 6px rgba(0,21,41, .35);
  display: flex;
  align-items: center;
}



/*
.el-m.enu-item:hover, .el-submenu__title:hover {
  color: #fff !important;
}
.el-submenu__title:hover i {
  color: #fff !important;
}
.el-menu-item.is-active {
  background-color: #05cc95 !important;
  border-radius: 0 23px 23px 0 !important;
  margin: 10px 17px 0 0;
  height: 46px;
  line-height: 46px;
  padding: 0 0 0 35px!important;
}
.el-menu .el-submenu.is-active,.el-menu .el-submenu .el-menu-item.is-active  {
  background-color: #05cc95 !important;
  border-radius: 0 23px 23px 0 !important;
  margin: 10px 17px 0 0;
  height: 46px;
  line-height: 46px;
  padding: 0 0 0 35px!important;
}
.el-menu .el-menu-item {
  color: #aeb5c4;
  margin: 10px 17px 0 0;
  height: 46px;
  line-height: 46px;
  padding: 0 0 0 35px!important;
  border-radius: 0 23px 23px 0 !important;

}
.el-menu .el-submenu__title {
  margin: 10px 17px 10px 0;
  color: #aeb5c4;
  height: 46px;
  line-height: 46px;
  padding: 0 0 0 35px!important;

  border-radius: 0 23px 23px 0!important;
}
.el-menu .el-submenu .el-menu-item {
  color: #aeb5c4;
  height: 46px;
  line-height: 46px;
  padding: 0 0 0 45px!important;
  font-size: 13px;
  border-radius: 0 23px 23px 0!important;
  margin: 10px 17px 10px 0;
}
*/
</style>
